package juc;

import java.util.concurrent.TimeUnit;
import java.util.concurrent.locks.Condition;
import java.util.concurrent.locks.LockSupport;
import java.util.concurrent.locks.ReentrantLock;

/**
 * @author liwuji
 * @date 2024/1/19
 * @desc
 **/
public class LockSupportDemo2 {
    public static void main(String[] args) throws InterruptedException {

        Thread thread = new Thread(() -> {
            System.out.println(Thread.currentThread().getName() + " come in");
            try {
                LockSupport.park();
            } catch (Exception e) {
                e.printStackTrace();
            }
            System.out.println(Thread.currentThread().getName() + "被唤醒");

        }, "t1");
   
        TimeUnit.SECONDS.sleep(1);
        new Thread(()->{
                try {
                    LockSupport.unpark(thread);
                    System.out.println(Thread.currentThread().getName()+" 发出通知");
                }catch (Exception e){
                    e.printStackTrace();
                }
        },"t2").start();
        TimeUnit.SECONDS.sleep(1);
        thread.start();
    }
}
